import 'package:flutter/material.dart';
import 'package:flutter_house_manager/pages/Login/index.dart';
import 'package:flutter_house_manager/pages/NoticeDetail/index.dart';
import 'package:flutter_house_manager/pages/Profile/index.dart';
import 'package:flutter_house_manager/pages/TabsPage/index.dart';
import 'package:flutter_house_manager/utils/TokenManager.dart';

Widget getRouteWidget() {
  return MaterialApp(
    routes: {
      '/': (context) => const TabsPage(),
      '/NoticeDetail': (context) => const NoticeDetail(),
      // '/Profile': (context) => const ProfilePage(),
      '/Login': (context) => const LoginPage()
    },
    initialRoute: '/',
    onGenerateRoute: (setting) {
      if (setting.name == '/Profile') {
        String token = tokenManager.getToken();
        if (token.isEmpty) {
          return MaterialPageRoute(builder: (context) =>  LoginPage(toName: setting.name,));
        } else {
      
          return MaterialPageRoute(builder: (context) => const ProfilePage());
        }
      }
      return null;
    },
  );
}
